package com.jingxi.portal.service;

import com.jingxi.common.pojo.JingXiResult;
import com.jingxi.common.util.HttpclientUtil;
import com.jingxi.common.util.JsonUtils;

import com.jingxi.model.TbContent;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ContentServiceImpl implements ContentService {

    @Value("${REST_BASE_URL}")
    private String REST_BASE_URL;
    @Value("${REST_INDEX_AD_URL}")
    private String REST_INDEX_AD_URL;

    @Override
    public String getContentList() {
        try {
            String result= HttpclientUtil.get("http://localhost:8082/rest/content/list/89");
            JingXiResult jingXiResult=new JingXiResult();
            jingXiResult=JingXiResult.formatToList(result,TbContent.class);
            List<TbContent>list=(List<TbContent>)jingXiResult.getData();
            List<Map>resultList=new ArrayList<>();
            for (TbContent tbContent:list){
                Map map=new HashMap();
                map.put("src",tbContent.getPic());
                map.put("height",240);
                map.put("width",670);
                map.put("srcB",tbContent.getPic2());
                map.put("widthB",550);
                map.put("heightB",240);
                map.put("href",tbContent.getUrl());
                map.put("alt",tbContent.getSubTitle());
                resultList.add(map);
            }
            return JsonUtils.objectToJson(resultList);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}
